/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package telaCadastros;

import managertelaCadastros.managerCadServicoProduto;

/**
 *
 * @author fumio
 */
public class CadServicoProduto extends javax.swing.JDialog {

    private static CadServicoProduto cadServicoProduto;
    private static managerCadServicoProduto managerCadServicoProduto;

    public static CadServicoProduto getInstance(managerCadServicoProduto mCadServicoProduto) {
        cadServicoProduto = new CadServicoProduto(null, true);
        cadServicoProduto.setTitle("Cadastro de Servico x Produto");
        managerCadServicoProduto = mCadServicoProduto;
        return cadServicoProduto;
    }

    public CadServicoProduto(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    private void LimpaTela() {
        edtCodServico.setText("");
        edtServico.setText("");
        edtPrecoConsumo.setText("");
        edtQuantidade.setText("");
        edtPrecoCusto.setText("");
        cmbUnidadeMedida.setSelectedIndex(0);

    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        edtCodServico = new javax.swing.JTextField();
        btnPesquisaServico = new javax.swing.JButton();
        edtServico = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        edtCodProduto = new javax.swing.JTextField();
        btnPesquisaProduto = new javax.swing.JButton();
        edtProduto = new javax.swing.JTextField();
        edtPrecoCusto = new javax.swing.JFormattedTextField();
        edtQuantidade = new javax.swing.JFormattedTextField();
        edtPrecoConsumo = new javax.swing.JFormattedTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        lblPrecoConsumo = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        btnAdicionar = new javax.swing.JButton();
        btnCancelarServico = new javax.swing.JButton();
        btnRemover = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblServicoProduto = new javax.swing.JTable();
        btnSair = new javax.swing.JButton();
        cmbUnidadeMedida = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createCompoundBorder(null, new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
        jPanel1.add(edtCodServico, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 30, 70, -1));

        btnPesquisaServico.setText("P");
        btnPesquisaServico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPesquisaServicoActionPerformed(evt);
            }
        });
        jPanel1.add(btnPesquisaServico, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 30, 60, -1));
        jPanel1.add(edtServico, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 30, 380, 30));

        jLabel1.setText("Serviço:");
        jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, -1, -1));

        jPanel2.setBorder(javax.swing.BorderFactory.createCompoundBorder(null, new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
        jPanel2.add(edtCodProduto, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 30, 70, 30));

        btnPesquisaProduto.setText("P");
        btnPesquisaProduto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPesquisaProdutoActionPerformed(evt);
            }
        });
        jPanel2.add(btnPesquisaProduto, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 30, 60, 30));
        jPanel2.add(edtProduto, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 30, 380, 30));
        jPanel2.add(edtPrecoCusto, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 150, 160, 30));
        jPanel2.add(edtQuantidade, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 90, 130, 30));
        jPanel2.add(edtPrecoConsumo, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 150, 130, 30));

        jLabel2.setText("Produto:");
        jPanel2.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, -1, 20));

        jLabel3.setText("Preço Custo:");
        jPanel2.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 130, -1, 20));

        lblPrecoConsumo.setText("Preço Consumo:");
        jPanel2.add(lblPrecoConsumo, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 130, -1, 20));

        jLabel5.setText("Quantidade:");
        jPanel2.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 70, -1, 20));

        btnAdicionar.setText("Adicionar");
        btnAdicionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAdicionarActionPerformed(evt);
            }
        });
        jPanel2.add(btnAdicionar, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 190, -1, 70));

        btnCancelarServico.setText("Cancelar");
        btnCancelarServico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarServicoActionPerformed(evt);
            }
        });
        jPanel2.add(btnCancelarServico, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 190, 80, 70));

        btnRemover.setText("Remover");
        btnRemover.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoverActionPerformed(evt);
            }
        });
        jPanel2.add(btnRemover, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 190, 90, 70));

        tblServicoProduto.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tblServicoProduto);

        jPanel2.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 270, 560, 160));

        btnSair.setText("Sair");
        btnSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSairActionPerformed(evt);
            }
        });
        jPanel2.add(btnSair, new org.netbeans.lib.awtextra.AbsoluteConstraints(440, 190, 80, 70));

        cmbUnidadeMedida.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Unidade", "Mililitros", " ", " " }));
        jPanel2.add(cmbUnidadeMedida, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 90, 160, -1));

        jLabel4.setText("Unidade Medida:");
        jPanel2.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 70, -1, -1));

        jPanel1.add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 70, 560, 430));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 489, Short.MAX_VALUE)
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-570)/2, (screenSize.height-531)/2, 570, 531);
    }// </editor-fold>//GEN-END:initComponents

    private void btnPesquisaServicoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPesquisaServicoActionPerformed
        // TODO add your handling code here:
        managerCadServicoProduto.carregaPesquisaServico();
    }//GEN-LAST:event_btnPesquisaServicoActionPerformed

    private void btnPesquisaProdutoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPesquisaProdutoActionPerformed
        // TODO add your handling code here:
        managerCadServicoProduto.carregaPesquisaProduto();
    }//GEN-LAST:event_btnPesquisaProdutoActionPerformed

    private void btnAdicionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAdicionarActionPerformed
        // TODO add your handling code here:
        managerCadServicoProduto.salvar();
    }//GEN-LAST:event_btnAdicionarActionPerformed

    private void btnCancelarServicoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarServicoActionPerformed
        // TODO add your handling code here:
        LimpaTela();
        edtCodServico.setEnabled(true);
        edtServico.setEnabled(true);
        btnPesquisaServico.setEnabled(true);
        edtCodServico.setText("");
        edtServico.setText("");
        edtCodServico.requestFocusInWindow();
    }//GEN-LAST:event_btnCancelarServicoActionPerformed

    private void btnRemoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoverActionPerformed
        // TODO add your handling code here:
        if (managerCadServicoProduto.remover()) {
            LimpaTela();
        }

    }//GEN-LAST:event_btnRemoverActionPerformed

    private void btnSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSairActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_btnSairActionPerformed
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JButton btnAdicionar;
    public javax.swing.JButton btnCancelarServico;
    public javax.swing.JButton btnPesquisaProduto;
    public javax.swing.JButton btnPesquisaServico;
    public javax.swing.JButton btnRemover;
    public javax.swing.JButton btnSair;
    public javax.swing.JComboBox cmbUnidadeMedida;
    public javax.swing.JTextField edtCodProduto;
    public javax.swing.JTextField edtCodServico;
    public javax.swing.JFormattedTextField edtPrecoConsumo;
    public javax.swing.JFormattedTextField edtPrecoCusto;
    public javax.swing.JTextField edtProduto;
    public javax.swing.JFormattedTextField edtQuantidade;
    public javax.swing.JTextField edtServico;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    public javax.swing.JLabel lblPrecoConsumo;
    public javax.swing.JTable tblServicoProduto;
    // End of variables declaration//GEN-END:variables
}
